package cjq.dao.impl;

import cjq.bean.Users;
import cjq.dao.UsersDao;
import cjq.util.DBUtils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class UsersDaoImpl implements UsersDao {

    @Override
    public Users getAll(String uname) {
        DBUtils dbUtils = new DBUtils();
        String sql = "select * from users where username = ?";
        List list = new ArrayList();
        list.add(uname);
        ResultSet rs = dbUtils.query(sql,list);

        Users users = new Users();
        try {
            if (rs.next()){
                users.setUsername(rs.getString("username"));
                users.setPhone(rs.getString("phone"));
                users.setAge(rs.getInt("age"));
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            dbUtils.closeall();
        }
        return users;
    }
}
